package org.leo.dm.example.base;

import org.leo.dm.component.reader.Reader;
import org.leo.dm.component.writer.Writer;
import org.leo.dm.util.ThreadPoolUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FlowDaemon {
	Logger log = LoggerFactory.getLogger(this.getClass());

	public void handle(ThreadPoolUtil threadPoolUtil, final Reader reader, final Writer writer) {
		threadPoolUtil.getPool().execute(new Runnable() {
			@Override
			public void run() {
				try {
					int countmsr = 1;
					int countmsw = 1;
					int counter = 0;
					boolean run = true;
					while (run) {
						Thread.sleep(1000);
						countmsr = (Integer) reader.getDaemonData().get("countms");
						countmsw = (Integer) writer.getDaemonData().get("countms");
						log.info("读取数据效率：" + countmsr);
						log.info("写入数据效率：" + countmsw);
						if (countmsr == 0 && countmsw == 0) {
							counter++;
						}
						if (counter > 2) {
							run = false;
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
		threadPoolUtil.shutdownPool();
	}
}
